<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="${pageContext.request.contextPath }/bootstrap/img/favicon.ico">
<link href="${pageContext.request.contextPath }/bootstrap/css/style.min.css?v=4.0.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/animate.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/bootstrap/css/jquery-confirm.css"/>
<link href="${pageContext.request.contextPath }/bootstrap/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<link href="${pageContext.request.contextPath }/bootstrapStyle/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet"/>
<title>设置利率</title>
</head>
<body class="gray-bg">
<div class="row wrapper wrapper-content animated fadeInRight">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-title">
				<h5>利率设置</h5>
			</div>
			<div class="ibox-content">
				<p>设置医生和医院的扣费利率，利率设置值范围是0.01%-100%</p>
			</div>
			<div class="ibox-content">
				<div class="row">
					<div class="col-sm-12">
						<div class="alert alert-info">
		                	<label class="control-label">当前医生利率为&nbsp;&nbsp;<a id="Pdocrate"></a></label>
                    	</div>
                    	<div class="alert alert-info">
		                	<label class="control-label">当前医院利率为&nbsp;&nbsp;<a id="Phosprate"></a></label>
                    	</div>
					</div>
					<form>
					<div class="col-sm-12">
				        <div class="col-sm-5">
                			<div class="form-group draggable">
		                    	<label class="control-label">设置医生扣费利率：</label>
		                        <div class="input-daterange input-group" id="datepicker">
				                    <input type="text" class="input-md form-control" onkeyup="num(this)" id="docrate" name="docrate" placeholder="利率不可超过100%，不得小于0.01%，保留两位小数"/>
				                    <span class="input-group-addon">%</span>
				                </div>
		                   	</div>
                		</div>
					</div>
					<div class="col-sm-12">
				        <div class="col-sm-5">
                			<div class="form-group draggable">
		                    	<label class="control-label">设置医院扣费利率：</label>
		                        <div class="input-daterange input-group" id="datepicker">
				                    <input type="text" class="input-md form-control" onkeyup="num(this)" id="hosprate" name="hosprate" placeholder="利率不可超过100%，不得小于0.01%，保留两位小数" />
				                    <span class="input-group-addon">%</span>
				                </div>
		                   	</div>
                		</div>
					</div>
					<div class="col-sm-12" style="margin-top: 20px;">
						<div class="col-sm-3 control-label">
				            <button type="button" class="btn btn-primary" onclick="Updatefundrate()" id="savebtn">提交</button>
				            <button type="reset" class="btn btn-reset">重置</button>
				        </div>
					</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

	<script src="${pageContext.request.contextPath }/bootstrap/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/jquery-confirm.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/bootstrap-datetimepicker.min.js"></script>
	<script src="${pageContext.request.contextPath }/bootstrapStyle/js/plugins/fancybox/jquery.fancybox.js"></script>
	<script type="text/javascript">
	function num(obj){
		obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
		obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
		obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
		obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
		obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
	}
	$(function(){
		loadrate();
	})
	function loadrate(){
		$.ajax({
			type:"post",
			url:"${pageContext.request.contextPath}/Main/SetRate/loadrate.action",
			async: true,
			success:function(data){
				if(data.code=='100'){
					$("#Pdocrate").html(data.docfefundrate+"%");
					$("#Phosprate").html(data.hospfefundrate+"%");
				}else{
					$.alert('获取当前来利率失败！');
				}
			},error:function(request){
				$.alert('获取当前利率，向服务器请求错误！');
			}
		});
	}
	function Updatefundrate(){
		var docfefundrate = $("#docrate").val();
		var hospfefundrate = $("#hosprate").val();
		if(docfefundrate=="" || hospfefundrate==""){
			$.alert('利率设置不可为空');
			return false;
		}
		if(docfefundrate<0.01 || docfefundrate>1 || hospfefundrate<0.01 || hospfefundrate>1){
			$.alert('利率设置超过范围');
			return false;
		}
		$.confirm({
		    title: '提示!',
		    content: '你确定提交修改？',
		    type: 'blue',
		    typeAnimated: true,
		    buttons: {
		    	确定: function () {
		    		$("#savebtn").html('<i class="fa fa-spinner fa-spin"></i>处理中...');
		    		$("#savebtn").prop('disabled',true);
		    		$.ajax({
		    			type:"post",
		    			url:"${pageContext.request.contextPath}/Main/SetRate/updatefundrate.action",
		    			async: true,
		    			data:"docfefundrate="+docfefundrate+"&hospfefundrate="+hospfefundrate,
		    			success:function(data){
		    				$("#savebtn").html('提交');
	    		    		$("#savebtn").prop('disabled',false);
		        			$.alert(data.msg);
		        			if(data.code==100){
		        				$("#Pdocrate").html(docfefundrate+"%");
		    					$("#Phosprate").html(hospfefundrate+"%");
		        			}
		    			},error:function(request){
		    				$.alert('获取当前利率，向服务器请求错误！');
		    				$("#savebtn").html('提交');
	    		    		$("#savebtn").prop('disabled',false);
		    			}
		    		});
		    	},
				取消: function () {},
		    }	
		});
	}
	</script>
</body>
</html>